package com.itfenghuang.day01.day02;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class A04_Response extends HttpServlet {
    /**
     * 1.常用的状态码
     *      1). 200    成功
     *      2). 302    重定向
     *      3). 404    请求资源未找到
     *      4). 500    服务器内部错误
     */
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //解决中文响应乱码问题
        resp.setContentType("text/html;charset=utf-8");

        //响应数据 ,HttpServletResponse
        //通过字节流响应浏览器
//        ServletOutputStream os = resp.getOutputStream();
//        OutputStreamWriter osw = new OutputStreamWriter(os);
//        osw.write("今天指腚是不行了");
//        os.write("做人鬼屎一点".getBytes());
//        os.write("<h1>鼠鼠</h1>".getBytes());

        //使用字符流响应数据
        PrintWriter writer = resp.getWriter();
        writer.write("<a href='#'>你有很多饭吃不下???</a>");

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
